package cn.jinjimi.app.entity.Item;

import cn.jinjimi.app.entity.Company;
import cn.jinjimi.app.entity.ZdbAge;
import cn.jinjimi.app.entity.ZdbInsurance;
import cn.jinjimi.app.entity.ZdbInsurancesType;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Roy
 * Date: 2017/3/20
 */

public class ZdbFilterItem {
    public int itemType;

    public static final int TypeHeader = 1;
    public static final int TypeCompany = 2;
    public static final int TypeInsureClass = 3;
    public static final int TypeAge = 4;

    public String headName;
    public Company company;
    public ZdbInsurance zdbInsurance;
    public ZdbAge zdbAge;

    public boolean isSelected;

    public ZdbFilterItem(int type, String headName) {
        this.itemType = type;
        this.headName = headName;
    }

    public ZdbFilterItem(int type, Company company, boolean isSelected) {
        this.itemType = type;
        this.company = company;
        this.isSelected = isSelected;
    }

    public ZdbFilterItem(int type, ZdbInsurance zdbInsurance, boolean isSelected) {
        this.itemType = type;
        this.zdbInsurance = zdbInsurance;
        this.isSelected = isSelected;
    }

    public ZdbFilterItem(int type, ZdbAge zdbAge, boolean isSelected) {
        this.itemType = type;
        this.zdbAge = zdbAge;
        this.isSelected = isSelected;
    }

    public static List<ZdbFilterItem> createCompanyItems(List<Company> datas) {
        List<ZdbFilterItem> zdbFilterItems = new ArrayList<>();
        if (datas != null && datas.size() > 0) {
            zdbFilterItems.add(new ZdbFilterItem(TypeHeader, "公司"));

            Company allCompany = new Company(null, "全部");
            zdbFilterItems.add(new ZdbFilterItem(TypeCompany, allCompany, true));

            for (Company company : datas) {
                zdbFilterItems.add(new ZdbFilterItem(TypeCompany, company, false));
            }
        }
        return zdbFilterItems;
    }

    public static List<ZdbFilterItem> createZdbInsuranceItems(List<ZdbInsurancesType> datas) {
        List<ZdbFilterItem> zdbFilterItems = new ArrayList<>();
        if (datas != null && datas.size() > 0) {
            zdbFilterItems.add(new ZdbFilterItem(TypeHeader, "险种"));

            ZdbInsurance allType = new ZdbInsurance();
            allType.setName("全部");
            zdbFilterItems.add(new ZdbFilterItem(TypeInsureClass, allType, true));

            for (ZdbInsurancesType zdbInsurancesType : datas) {
                for (ZdbInsurance zdbInsurance : zdbInsurancesType.getSubclasses()) {
                    zdbInsurance.parentId = zdbInsurancesType.getId();
                    zdbFilterItems.add(new ZdbFilterItem(TypeInsureClass, zdbInsurance, false));
                }
            }
        }
        return zdbFilterItems;
    }

    public static List<ZdbFilterItem> createZdbAgeItems(List<ZdbAge> datas) {
        List<ZdbFilterItem> zdbFilterItems = new ArrayList<>();
        if (datas != null && datas.size() > 0) {
            zdbFilterItems.add(new ZdbFilterItem(TypeHeader, "年龄"));

            ZdbAge allAge = new ZdbAge();
            allAge.name = "不限年龄";
            zdbFilterItems.add(new ZdbFilterItem(TypeAge, allAge, true));

            for (ZdbAge zdbAge : datas) {
                zdbFilterItems.add(new ZdbFilterItem(TypeAge, zdbAge, false));
            }
        }
        return zdbFilterItems;
    }
}
